package org.online.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.online.conmon.Const;
import org.online.entity.User;

/**
 * 查看在线用户列表
 * 
 * @author Administrator
 *
 */
@WebServlet("/listOnineUser.do")
public class ShowOnlineUserServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		PrintWriter out = resp.getWriter();

		// 获取上下文对象
		ServletContext context = req.getServletContext();

		// 在上下文对象中，获取map集合
		@SuppressWarnings("unchecked")
		Map<String, User> map = (Map<String, User>) context.getAttribute(Const.ONLINE_USER_MAP);

		
		out.print("<!DOCTYPE html>");
		out.print("<html>");
		out.print("<head>");
		out.print("<meta charset='UTF-8'>");
		out.print("<title>在线用户列表</title>");
		out.print("</head>");
		out.print("<body>");
		out.print("<h1>在线用户列表</h1>");
		
		// 循环遍历map集合
		for(String username : map.keySet()) {
			out.print("<h5>" + username + "</h5>") ;
		}
		
		out.print("</body>");
		out.print("</html>");
		
		// 关闭对象
		out.flush();
		out.close();
	}

}
